<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <script src="https://cdn.staticfile.org/angular.js/1.4.6/angular.min.js"></script>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form"  lay-filter="example"  >
        <form  ng-app="myApp" ng-controller="customersCtrl" ng-cloak name="myForm">
            <div  class="layui-tab layui-tab-brief" >
                <ul class="layui-tab-title">
                    <li class="layui-this"> 
                        <i class="layui-icon" >基础设置</i>
                    </li>
                    <li ng-repeat="(key,class) in data.class">
                        <i class="layui-icon">{{class.title}}</i>
                    </li>
                </ul>
                <div class="layui-form-item"   style="margin-left: 899px; margin-top: 10px;">
                    <div class="layui-input-block">
                        <!-- lay-filter="saveBtn" -->
                        <button class="layui-btn layui-btn-normal" lay-submit   ng-click="subForm()" >确认保存</button>
                    </div>
                </div>
                <div class="layui-tab-content" >
                    <input type="hidden" name="id"  id="id" ng-model="data.id" >
                    <div class="layui-tab-item layui-show"  >
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label required" >项目</label>
                                <div class="layui-input-inline ">
                                    <select  ng-model="data.project_id" id="project_id" lay-verify="required" name="project_id">
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-inline">
                                <div class="layui-input-block">
                                </div>
                            </div>
                        </div> 
                    </div>
                    
                    <div class="layui-tab-item" ng-repeat="(key,class) in data.class" >
                        <div class="layui-input-block">
                            <table class="layui-table">
                                <tbody>
                                <tr>
                                    <td>收费比例    
                                        <input type="radio" style="display: initial;"  name="{{$index}}open_jine"  value="0" ng-model="class.open_jine"  checked=""/>关闭
                                        <input type="radio" style="display: initial;"  name="{{$index}}open_jine"  value="1" ng-model="class.open_jine" />开启
                                    </td>
                                    <td>  
                                        用户扣除收费折扣:                            
                                        <input type="text" name="{{$index}}user_jine_zk" id="{{$index}}user_jine_zk"  ng-model="class.user_jine_zk"  class="layui-input">
                                    </td>
                                    <td>
                                        作者获得收费折扣:
                                        <input type="text" name="{{$index}}tea_jine_zk" id="{{$index}}tea_jine_zk"  ng-model="class.tea_jine_zk"  class="layui-input">
                                    </td>
                                </tr>
                                <tr>
                                    <td>积分比例   
                                        <input type="radio" style="display: initial;"  name="{{$index}}open_jifen"  value="0" ng-model="class.open_jifen"  checked=""/>关闭
                                        <input type="radio" style="display: initial;"  name="{{$index}}open_jifen"  value="1" ng-model="class.open_jifen" />开启
                                    </td>
                                    <td>  
                                        用户扣除积分折扣:                            
                                        <input type="text" name="{{$index}}user_jifen_zk" id="{{$index}}user_jifen_zk"  ng-model="class.user_jifen_zk"  class="layui-input">
                                    </td>
                                    <td>
                                        作者获得积分折扣:
                                        <input type="text" name="{{$index}}tea_jifen_zk" id="{{$index}}tea_jifen_zk"  ng-model="class.tea_jifen_zk"  class="layui-input">
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                            <table class="layui-table">
                                <thead>
                                <tr>
                                    <th>行为</th>
                                    <th>用户获得积分比例</th>
                                    <th>作者获得积分比例</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr  ng-repeat="(key,score) in class.scores">
                                    <td>{{score.title}}</td>
                                    <td>                                
                                        <input type="text" name="{{score.uservalue}}"  ng-model="score.uservalue" class="layui-input">
                                    </td>
                                    <td>                                
                                        <input type="text" name="{{score.teavalue}}"  ng-model="score.teavalue"  class="layui-input">
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        
    </div>
    
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js" charset="utf-8"></script>
<script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function ($scope, $http,$location) {
        $scope.jifen =[
                {"type":"getEssayList","title":"看文章","uservalue":1,"teavalue":1},
                {"type":"getSunEssayList","title":"看连载","uservalue":1,"teavalue":1},
                {"type":"addLikes","title":"操作点赞","uservalue":1,"teavalue":1},
                {"type":"addComments","title":"发表评分","uservalue":1,"teavalue":1},
                ];
        $scope.data ={"project_id": '0',"class":[]};
        layui.use(['form','upload','http'], function () {
            var form = layui.form,
                layer = layui.layer,
                uploadInst = layui.upload,
                http  = layui.http,
                apiurl =http.api,
                $ = layui.$;
            http.verifyToken();
            var id  = http.getQueryString('id');
            if(id){
                getProject(function(){
                    projectIntegralIfno();
                });
            }else{
                getProject();
                getUserlevelList()
            }

            function getUserlevelList(){
                http.httpajax("Personal/userlevelList",{},"POST",function(res) {
                    if(res.code == '0000'){
                        $scope.data.class =[];
                        for(var i =0;i<res.data.length;i++){
                            $scope.data.class.push({
                                "id":res.data[i].id,"title":res.data[i].name,"open_jifen":1,"open_jine":1,
                                "user_jifen_zk":0,"tea_jifen_zk":0,"user_jine_zk":0,"tea_jine_zk":0,
                                "scores":$scope.jifen});
                        }
                        $scope.$apply();
                    }else{ 
                        layer.msg(res.msg,{time:1000,icon:2});
                    } 
                });
            }
                
            function projectIntegralIfno(){
                http.httpajax("Personal/projectIntegralList",{'id':id},"POST",function(res) {
                    if(res.code == '0000'){
                        form.render();
                        form.val('example', res.data)
                        $('#id').val(res.data.id);
                        // $scope.data.project_id=res.data.project_id;
                        // $scope.data.class=res.data.class;
                        // $scope.data.id=res.data.id;
                        $scope.data=res.data;
                        $scope.$apply();
                        console.error("$scope.data",$scope.data);
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            }

            function getProject(callback){
                http.httpajax("Personal/projectList",{},"POST",function(res) {
                    if(res.code == '0000'){
                        for(var i =0;i<res.data.length;i++){
                            $("#project_id").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
                        }
                        layui.form.render("select");
                        callback();
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            }

            form.on("select", function(data){
                $scope.data.project_id = data.value;
                $scope.$apply();
            });

            $scope.subForm = function () {
                var str = angular.toJson( $scope.data);//str为字符串
                var abj = JSON.parse(str);//json为对象
                http.httpajax("Personal/projectIntegralAdData", abj,"POST",function(res) {
                    if(res.code === '0000'){
                        layer.msg(res.msg,{time:1000,icon:1},function(){
                            // 关闭弹出层
                            layer.close();
                            window.parent.location.reload();//刷新父页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                    }
                });
            };

        });
      
        

        
    });
</script>
</body>
</html>